package cn.hs.controller;/**
 * @author Jovan Hou 2024/10/22
 **/

import cn.hs.entity.Demo;
import cn.hs.entity.Fm;
import cn.hs.entity.Systemuser;
import cn.hs.service.FmService;
import cn.hs.util.Result;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName FmController
 * @Description TODO
 * @Author CnYuu
 * @Date 2024年10月22日 20:53
 * @Version 1.0
 */
@RestController
@RequestMapping("/fm")
public class FmController
{
    @Autowired
    private FmService service;
    @GetMapping("/selectAll")
    public Result selectAll(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
                              @Param("id")
                             Integer id,
                             @Param("name")
                            String name,
                            @Param("img")
                            String img,
                            @Param("music")
                            String music
                            ){
        Fm fm = new Fm(id,name,music,img);
        PageInfo fms = service.findAll(pageNum, pageSize, fm);
        // 用户不存在
        return Result.success(fms);
    }

    @PostMapping("/insert")
    public Result insert(
          @RequestBody
          Fm fm
    ){
        int insert = service.insert(fm);
        return Result.success(insert);
    }

    @GetMapping("/delete")
    public Result delete(
            @Param("id")
           Integer id
    ){
        int i = service.deleteById(id);
        return Result.success(i);
    }




    @PutMapping("/update")
    public Result update(
           @RequestBody Fm fm
    ){
        int update = service.update(fm);
        return Result.success(update);
    }


    @GetMapping("/selectById")
    public Result selectById(
            @Param("id")
            Integer id){
        Fm fm = service.selectById(id);
        return Result.success(fm);
    }
    }

